#include #include #include #include using namespace std; //i is passed to the function fun "by value" void fun(int i) { cout << i << endl; i = 9; cout << i << endl; } //i is passed to the function fun2 "by reference" void fun2(int& i) { cout << i << endl; i = 9; cout << i << endl; } void swap(int& x, int& y) { int temp = x; x = y; y = temp; } int random(int lowBound, int highBound) { return (rand() % (highBound - lowBound + 1) + lowBound); } int greatestCommonFactor(int x, int y) { int result = 1; for(int i = 2; i <= x && i <= y; i++) { if(x%i == 0 && y%i==0) { result = i; } } return result; } void reduceFunction(int& numerator, int& denominator) { int gcf = greatestCommonFactor(numerator, denominator); numerator /= gcf; denominator /= gcf; } void main() { int x = 88; int y = 77; reduceFunction(x, y); cout << x << "/" << y << endl; //int y = 0; //int w = 77; //int& x = y; //x = w; //y = 3; //cout << x << endl; //fun2(y); //cout << y << endl; //int q = 9; //int p = 88; //swap(q,p); srand((unsigned int)time(NULL)); int rolls2 = 0; int rolls3 = 0; int rolls4 = 0; int rolls5 = 0; int rolls6 = 0; int rolls7 = 0; int rolls8 = 0; int rolls9 = 0; int rolls10 = 0; int rolls11 = 0; int rolls12 = 0; for(int i = 0; i < 1000000;i++) { switch(random(1,6) + random(1,6)) { case 2: rolls2++; break; case 3: rolls3++; break; case 4: rolls4++; break; case 5: rolls5++; break; case 6: rolls6++; break; case 7: rolls7++; break; case 8: rolls8++; break; case 9: rolls9++; break; case 10: rolls10++; break; case 11: rolls11++; break; case 12: rolls12++; break; } cout << random(1,6) + random(1,6) << endl; //char c; //cin >> c; system("pause"); } cout << rolls2 << endl; cout << rolls3 << endl; cout << rolls4 << endl; cout << rolls5 << endl; cout << rolls6 << endl; cout << rolls7 << endl; cout << rolls8 << endl; cout << rolls9 << endl; cout << rolls10 << endl; cout << rolls11 << endl; cout << rolls12 << endl; cout << "Win " << rolls7 + rolls11 << endl; cout << "Lose " << rolls2 + rolls3 + rolls12 << endl; cout << "Point " << rolls4 + rolls5 + rolls6 + rolls8 + rolls9 + rolls10 << endl; }